import { formatUrl, getActiveStr } from "./utils";

export function renderHouseInfo(data) {
  // 售价、户型、面积、装修、类型、朝向、楼层
  let html = "";
  const getHtml = (title, value) => {
    if (!value) return "";
    return `<li><span>${title}：</span>${value}</li>`;
  };

  html += getHtml("类 型", data.buildType);
  html += getHtml("装 修", data.decorateType);

  if (data.delegationType == "SALES") {
    html += getHtml("售 价", data.totalPrice);
  } else {
    html += getHtml("月 租", data.totalPrice);
  }

  html += getHtml("户 型", data.roomHall);
  html += getHtml("面 积", data.buildSize);
  html += getHtml("朝 向", data.direction);

  $(".layer-house-info .house-info").html(html);
}

export function addEventListener() {
  $(".js-house-info").click(() => {
    $(".layer-house-info").toggle();
  });
  $(".layer-house-info .close").click(() => {
    $(".layer-house-info").toggle();
  });

  $(".layer-mask").click(() => {
    $(".layer-pano-share").toggle();
  });

  $(".js-pano-share").click(() => {
    const appName = formatUrl.getQuery("appName");
    switch (appName) {
      case "jjrjs":
        wx.miniProgram.postMessage({
          data: {
            isGoZhaofang: true,
          },
        });

        wx.miniProgram.navigateBack();
        break;
      case "zhaofang":
        $(".layer-pano-share").toggle();
        $(".share-tip").css("right", "60px");

        break;
      case "h5":
        $(".layer-pano-share").toggle();
        $(".share-tip").css("right", "20px");

        break;

      default:
        break;
    }
  });
}

export function renderJjrInfo(data) {
  let defaultHead = "images/default_head.png";
  let src = data.avatar || defaultHead;

  $("#avatar-url").attr("src", src);
  $(".o-name").text(getActiveStr(data.realName, 14) || "");
  // $("#jjr-tel").attr("href", `tel:${data.mobile}`);
}
